package de.justphil.tcg.tcgserver.commons.util;

import de.justphil.tcg.tcgserver.commons.exceptions.TCGException;
import de.justphil.tcg.tcgserver.commons.management.DataManager;

public class OTPHelper {

	public static String generateOTP(DataManager dataManager, long gameId) {
		String s = null;
		
		while (s == null) {
			try {
				s = OTPGenerator.otp(gameId);
				dataManager.getNewGameByOTP(s); // throws TCGException if return value would be null
				s = null;
			}
			catch (TCGException ignored) {
				
			}
		}
		
		return s;
	}
	
}
